/*
 *  Copyright 2011 yura.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
package org.opu.db_vdumper.ui.component.tabel.models;

import java.awt.Component;
import java.awt.Image;
import javax.swing.JComponent;
import org.opu.db_vdumper.ui.View;

/**
 *
 * @author Potochnak Yana
 */
public abstract class SelectedComponentImpl<T extends Model> extends JComponent
    implements SelectedComponent<T> {

    protected Image selectBorder = null;
    protected Image selectErrorBorder = null;
    protected Image selectWarningBorder = null;
    protected Image errorBorder = null;
    protected Image warningBorder = null;

    @Override
    public Image getErrorBorder() {
        return errorBorder;
    }

    @Override
    public void setErrorBorder(Image errorBorder) {
        this.errorBorder = errorBorder;
    }

    @Override
    public Image getSelectBorder() {
        return selectBorder;
    }

    @Override
    public void setSelectBorder(Image selectBorder) {
        this.selectBorder = selectBorder;
    }

    @Override
    public Image getSelectErrorBorder() {
        return selectErrorBorder;
    }

    @Override
    public void setSelectErrorBorder(Image selectErrorBorder) {
        this.selectErrorBorder = selectErrorBorder;
    }

    @Override
    public Image getSelectWarningBorder() {
        return selectWarningBorder;
    }

    @Override
    public void setSelectWarningBorder(Image selectWarningBorder) {
        this.selectWarningBorder = selectWarningBorder;
    }

    @Override
    public Image getWarningBorder() {
        return warningBorder;
    }

    @Override
    public void setWarningBorder(Image warningBorder) {
        this.warningBorder = warningBorder;
    }
    
    /**
     *  Return image to draw border
     * @return image to draw border
     */
    protected Image getImageBorder(){
        Image toDraw = null;
        Model model = getViewModel();

        if (model.isSelected()) {
            toDraw = selectBorder;

            if (model.isHaveError()) {
                if (selectErrorBorder != null) {
                    toDraw = selectErrorBorder;
                } else {
                    toDraw = errorBorder;
                }
            } else if (model.isHaveWarning()) {
                if (selectWarningBorder != null) {
                    toDraw = selectWarningBorder;
                } else {
                    toDraw = warningBorder;
                }
            }
        } else if (model.isHaveError()) {
            toDraw = errorBorder;
        } else if (model.isHaveWarning()) {
            toDraw = warningBorder;
        }

        return toDraw;
    }


    @Override
    public void deselect() {
        getViewModel().setSelected(false);
    }

    @Override
    public void select() {
        getViewModel().setSelected(true);
    }

    @Override
    public Component asComponent() {
        return this;
    }
    
}
